package com.example.a2205_fx;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.view.MenuItem;

import com.blankj.utilcode.util.ToastUtils;
import com.example.a2205_fx.adapter.MyFragmentAdapter;
import com.example.a2205_fx.base.BaseViewActivity;
import com.example.a2205_fx.databinding.ActivityDouBinding;
import com.example.a2205_fx.fragment.HomeFragment;
import com.example.a2205_fx.fragment.MineFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

public class DouActivity extends BaseViewActivity<ActivityDouBinding> {
    List<Fragment> list = new ArrayList<>();
    MyFragmentAdapter myFragmentAdapter;

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        list.add(new HomeFragment());
        list.add(new MineFragment());
        myFragmentAdapter = new MyFragmentAdapter(this,list);
        binding.vp.setAdapter(myFragmentAdapter);
        //上下联动
        binding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                switch (position){
                    case 0:
                        binding.bottom.getMenu().getItem(0).setChecked(true);
                        break;
                    case 1:
                        binding.bottom.getMenu().getItem(2).setChecked(true);
                        break;
                }
            }
        });

        binding.bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.home:
                        binding.vp.setCurrentItem(0);
                        break;
                    case R.id.fabu:
                        ToastUtils.showLong("点击了中间的菜单");
                        break;
                    case R.id.mine:
                        binding.vp.setCurrentItem(1);
                        break;
                }
                return false;
            }
        });
        //设置一个小圆点或者数量
        binding.bottom.getOrCreateBadge(R.id.mine).setNumber(2);

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_dou;
    }
}